package com.softdev.controller;

import com.softdev.common.R;
import com.softdev.pojo.Risk;
import com.softdev.service.RiskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api("风险操作")
@Slf4j
@RestController
@RequestMapping("/risk")
public class RiskController {

    @Resource
    private RiskService riskService;

    @ApiOperation("新建风险")
    @PostMapping
    public R<String> add(@RequestBody Risk risk) {

        if (riskService.add(risk)) {
            return R.success("风险创建成功！");
        }

        return R.error("风险创建失败...");
    }

    @ApiOperation("新建风险")
    @DeleteMapping
    public R<String> add(Long[] riskIds) {

        if (riskService.remove(riskIds)) {
            return R.success("风险删除成功！");
        }

        return R.error("风险删除失败...");
    }

    @ApiOperation("查看风险")
    @GetMapping
    public R<List<Risk>> getAll() {

        List<Risk> risks = riskService.getAll();

        return R.success(risks);
    }

}
